<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Linq" %>
<%@ Import Namespace="Vit.Web.Models" %>
<script runat="server">
    protected IEnumerable<XElement> Menu
    {
        get
        {
            IEnumerable<XElement> menu = this.Model as IEnumerable<XElement>;
            if (menu == null)
            {
                WebSite site = ((Vit.Web.VitApplication)this.Context.ApplicationInstance).CurrentSite;
                string path = Server.MapPath(site.CurrentPage.Menu.Path);
                if (System.IO.File.Exists(path))
                {
                    XDocument doc = XDocument.Load(path);
                    menu = doc.Root.Elements();
                }
            }
            return menu;
        }
    }
</script>
<% if(Menu != null){ %>
<ul class="menu">
    <% foreach (XElement ele in Menu)
       { %>
        <li>
            <a href='<%= ele.AttributeValue("url","javascript:void();") %>'><%= Html.Encode(Html.Localize(ele.AttributeValue("caption", ele.AttributeValue("name", "NAME")))) %></a>
            <% Html.RenderPartial("Menu", ele.Elements()); %>
        </li>
    <%} %>
</ul>
<%} %>